﻿using IterationLife.Datas;
using IterationLife.Educations.Models;
using IterationLife.Educations.Queries;
using IterationLife.Educations.Repositories;
using IterationLife.PlatformBackEnd.AppServices.Contracts.Educations;
using IterationLife.PlatformBackEnd.AppServices.Dtos.Educations;
using Util.Applications;
using Util.Datas.Queries;
using Util.Domains.Trees;

namespace IterationLife.PlatformBackEnd.AppServices.Impl.Educations {
    /// <summary>
    /// 课程大纲服务
    /// </summary>
    public class SyllabusService : TreeServiceBase<Syllabus, SyllabusDto, SyllabusQuery>, ISyllabusService {
        /// <summary>
        /// 初始化课程大纲服务
        /// </summary>
        /// <param name="unitOfWork">工作单元</param>
        /// <param name="syllabusRepository">课程大纲仓储</param>
        public SyllabusService( IApplicationUnitOfWork unitOfWork, ISyllabusRepository syllabusRepository )
            : base( unitOfWork, syllabusRepository ) {
            SyllabusRepository = syllabusRepository;
        }
        
        /// <summary>
        /// 课程大纲仓储
        /// </summary>
        protected ISyllabusRepository SyllabusRepository { get; set; }
        
        /// <summary>
        /// 转换为数据传输对象
        /// </summary>
        /// <param name="entity">实体</param>
        protected override SyllabusDto ToDto( Syllabus entity ) {
            return entity.ToDto();
        }

        /// <summary>
        /// 转换为实体
        /// </summary>
        /// <param name="dto">数据传输对象</param>
        protected override Syllabus ToEntity( SyllabusDto dto ) {
            return dto.ToEntity();
        }
        
        /// <summary>
        /// 创建查询对象
        /// </summary>
        /// <param name="param">课程大纲查询实体</param>
        protected override IQueryBase<Syllabus> CreateQuery( SyllabusQuery param ) {
            return new Query<Syllabus>( param )
                .Filter( new TreeCriteria<Syllabus>( param ) );
        }
    }
}